package com.ddh.codeduck.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codeduck.pojo.entity.SysDictData;
import com.codeduck.pojo.req.SysDictDataPageReq;
import com.ddh.codeduck.service.ISysDictDataService;
import com.ddhcodeduck.common.result.BaseResponse;
import com.ddhcodeduck.common.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 字典数据表 前端控制器
 * </p>
 *
 * @author ddh
 * @since 2025-07-11
 */
@RestController
@RequestMapping("/sys-dict-data")
@Api(tags = "字典数据表")
public class SysDictDataController {
    @Resource
    private ISysDictDataService sysDictDataService;

    /**
     * 字典数据列表(分页)
     *
     * @param sysDictDataPageReq
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("字典数据列表(分页)")
    public BaseResponse<IPage<SysDictData>> sysDictDataPage(@RequestBody SysDictDataPageReq sysDictDataPageReq) {
        IPage<SysDictData> page = sysDictDataService.sysDictDataPage(sysDictDataPageReq);
        return ResultUtils.success(page);
    }

    @GetMapping("/getById")
    @ApiOperation("根据id查询字典数据")
    public BaseResponse<SysDictData> sysDictDataGetById(@RequestParam("id") String id) {
        SysDictData sysDictData = sysDictDataService.getById(id);
        return ResultUtils.success(sysDictData);
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation("新增或者修改字典数据表")
    public BaseResponse<Boolean> sysDictDataSaveOrUpdate(@RequestBody SysDictData sysDictData) {
        return ResultUtils.success(sysDictDataService.saveOrUpdate(sysDictData));
    }

    @PostMapping("/removeBatchByIds")
    @ApiOperation("批量删除字典数据表")
    public BaseResponse<Boolean> sysDictDataRemoveBatchByIds(@RequestBody List<String> ids) {
        return ResultUtils.success(sysDictDataService.removeBatchByIds(ids));
    }
}
